package com.victualler.product.vender.contoller.impl;

import com.victualler.core.base.controller.impl.BaseRestControllerImpl;
import com.victualler.core.common.dto.PageDto;
import com.victualler.product.vender.contoller.VenderController;
import com.victualler.product.vender.dto.request.VenderRequestDto;
import com.victualler.product.vender.entity.VenderMainDao;
import com.victualler.product.vender.dto.VenderInfoDto;
import com.victualler.product.vender.repository.VenderMainQueryRepository;
import com.victualler.product.vender.repository.VenderMainRepository;
import com.victualler.product.vender.service.VenderInfoService;
import com.victualler.product.vender.service.VenderMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Guoshichang
 * @Date: Create in 23:28 2018/4/18
 * @Discription:
 */
@RestController
@RequestMapping("/product/vender")
public class VenderControllerImpl extends BaseRestControllerImpl<VenderMainDao,VenderMainRepository,VenderMainQueryRepository,VenderMainService> implements VenderController {
    @Autowired
    VenderInfoService venderInfoService;

    /**
     * 保存厂商信息
     * @param venderInfoDto
     * @return
     */
    @RequestMapping("saveVenderInfo")
    @Override
    public VenderInfoDto saveVenderInfoDto(@RequestBody VenderInfoDto venderInfoDto) {
        this.venderInfoService.save(venderInfoDto);
        return venderInfoDto;
    }

    /**
     * 获取厂商信息byid
     * @param id
     * @return
     */
    @RequestMapping("getVender/{id}")
    @Override
    public VenderInfoDto getVenderInfoDtoById(@PathVariable("id") Long id) {
        VenderInfoDto result = venderInfoService.getById(id);
        return result;
    }


    @RequestMapping("updateVender")
    @Override
    public VenderInfoDto updateVender(@RequestBody VenderInfoDto venderInfoDto) {
        //更新 保存
        this.venderInfoService.updateVender(venderInfoDto);
        return venderInfoDto;
    }


    /**
     * @author Guoshichang
     * @since 13:39 on 2018/7/7.
     * @param venderRequestDto
     * @Function  根据条件入参venderRequestDto动态分页查询权限
     */
    @RequestMapping("/getByRequestDto")
    public PageDto<VenderMainDao> getByRequestDto(@RequestBody VenderRequestDto venderRequestDto, @RequestParam("pageNo") int pageNo, @RequestParam("limit") int limit) {
        return this.baseService.getByRequestDto(venderRequestDto,pageNo,limit);
    }

}
